Imports System.Xml
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' where do we want to get the XML from...
        Dim filename As String = _
            "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Address Book\Address Book\bin\Debug\AddressBook.xml"
        ' open the document...
        Dim reader As New XmlTextReader(filename)
        ' move to the start of the document...
        reader.MoveToContent()
        ' start working through the document...

        Dim addressData As Collection = Nothing
        Dim elementName As String = Nothing
        Do While reader.Read
            ' what kind of node to we have?
            Select Case reader.NodeType
                ' is it the start of an element?
                Case XmlNodeType.Element
                    ' if it's an element start, is it "Address"?
                    If reader.Name = "Address" Then
                        ' if so, create a new collection...
                        addressData = New Collection()
                    Else
                        ' if not, record the name of the element...
                        elementName = reader.Name
                    End If
                    ' if we have some text, try storing it in the 
                    ' collection...
                Case XmlNodeType.Text
                    ' do we have an address?
                    If Not addressData Is Nothing Then
                        addressData.Add(reader.Value, elementName)
                    End If
                    ' is it the end of an element?
                Case XmlNodeType.EndElement
                    ' if it is, we should have an entire address stored...
                    If reader.Name = "Address" Then
                        ' try to create a new listview item...
                        Dim item As String = Nothing
                        Try
                            item = addressData("firstname") & _
                                   " " & addressData("lastname")
                            item &= " (" & addressData("email") & ")"
                        Catch
                        End Try
                        ' add the item to the list...
                        lstEmails.Items.Add(item)
                        ' reset...
                        addressData = Nothing
                    End If
            End Select
        Loop

    End Sub
End Class
